<template>
  <div>
    <span class="text-blue pointer" @click="toEdit">
      {{ data.waybillNo }}
    </span>
    <el-tooltip effect="dark" content="点击复制" placement="bottom">
      <i
        class="el-icon-copy-document tag-read"
        :data-clipboard-text="data.waybillNo"
        @click="copy"
      ></i>
    </el-tooltip>
  </div>
</template>

<script>
import Clipboard from "clipboard";

export default {
  props: ["row", "data", "more"],

  methods: {
    toEdit() {
      let way = "";
      const sw = this.data.shippingWay;
      const id = this.data.id;
      if (sw == "ZX" || sw == "AIR") {
        way = 1;

        const url = `#/blank/waybill__airfreightmerge__main?shippingway=${way}&waybillId=${id}`;
        window.open(url, "_blank");
      } else if (sw == "FCL" || sw == "LCL") {
        way = 0;
        const url = `#/blank/waybill__seafreightmerge__main?shippingway=${way}&waybillId=${id}`;
        window.open(url, "_blank");
      } else if (sw == "TH" || sw == "HWC" || sw == "OT") {
        const url = `#/blank/waybill__abroadwaybilledit__main?pid=${id}`;
        window.open(url, "_blank");
      } else if (sw == "HD") {
        if (this.data.waybillNo.indexOf("HDA") > -1) {
          way = 1;
          const url = `#/blank/waybill__airfreightHD__main?shippingway=${way}&waybillId=${id}`;
          window.open(url, "_blank");
        } else if (this.data.waybillNo.indexOf("HDS") > -1) {
          way = 0;
          const url = `#/blank/waybill__seafreightHD__main?shippingway=${way}&waybillId=${id}`;
          window.open(url, "_blank");
        }
      } else {
        way = 0;
        const url = `#/blank/waybill__seafreightmerge__main?shippingway=${way}&waybillId=${id}`;
        window.open(url, "_blank");
      }
    },
    copy() {
      var clipboard = new Clipboard(".tag-read");
      clipboard.on("success", e => {
        this.$message.success("复制成功");
        // 释放内存
        clipboard.destroy();
      });
      clipboard.on("error", e => {
        // 不支持复制
        this.$message.error("该浏览器不支持自动复制");
        // 释放内存
        clipboard.destroy();
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.padding-l-sm {
  padding-left: 2px;
}
</style>
